package com.kgc.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.kgc.entity.Result;
import com.kgc.pojo.SellerInfo;
import com.kgc.service.BackSellerInfoService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author : nanqiong
 * @date：Created in 2020/11/19
 * @description:
 * @nersion: 1.0
 */
@Slf4j
@RestController
@RequestMapping("seller")
public class BackSellerController {


    @Autowired
    private BackSellerInfoService backSellerInfoService;

    @PostMapping("/login")
    public Result login (String username,String password) {
        log.info("BackSellerController login...");
        QueryWrapper<SellerInfo> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("username",username);

        SellerInfo sellerInfo = backSellerInfoService.getOne(queryWrapper);
        if (sellerInfo == null) {
            log.info("用户名不正确");
            return new Result(false, "用户名不正确");

        }
        if (sellerInfo.getPassword().equals(password)){
            // 把用户对象放入session中
            // request.getSession(true).setAttribute(SESSION_KEY_USER,user);
            log.info("登录成功");
            return  new Result(true,"登录成功");
        }else{
            log.info("密码错误");
            return new Result(false,"密码错误");
        }
    }

    /**
     * 退出登录
     * @return
     * @prams
     */

    @GetMapping("/logout")
    public Result logout () {
        return new Result(true,"退出成功");
    }

    /**
     * 用户列表
     * @return用户列表
     * @prams无
     */
    @PostMapping("sellerList")
    public Result sellerList(){
        List<SellerInfo> sellerInfoList = backSellerInfoService.list();
        return new Result(true,"用户列表",sellerInfoList);
    }
}
